package main

import (
	"gitee.com/lzqysoft/ilive/controllers"
	_ "gitee.com/lzqysoft/ilive/initial"
	_ "gitee.com/lzqysoft/ilive/routers"

	"strconv"

	"github.com/beego/i18n"

	"github.com/astaxie/beego"

	"github.com/astaxie/beego/orm"
	"github.com/astaxie/beego/plugins/cors"
	//	_ "github.com/astaxie/beego/session/redis"
	//	_ "github.com/astaxie/beego/session/ssdb"
	//	_ "github.com/lib/pq"
)

func main() {
	//	beego.SetLevel(beego.LevelInformational)
	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
		beego.SetLevel(beego.LevelDebug)
		orm.Debug = false
	}
	//	orm.Debug = true
	beego.SetLogger("file", `{"filename":"logs/app.log"}`)
	beego.BConfig.WebConfig.StaticDir["/imgs"] = "imgs"
	//	beego.SetLogFuncCall(true)
	//		beego.BConfig.Log.Outputs["file"]=""
	beego.BConfig.Log.AccessLogs = true
	logLevel, _ := strconv.Atoi(beego.AppConfig.String("log_level"))
	if beego.BConfig.RunMode == "prod" {
		beego.SetLevel(logLevel)
	}

	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowOrigins:     []string{"*"},
		AllowMethods:     []string{"OPTIONS", "HEAD", "GET", "POST", "PUT", "PATCH", "DELETE"},
		AllowHeaders:     []string{"Origin", "Accept", "Content-Type", "Authorization", "x-requested-with", "X-Requested-With"},
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,
	}))
	beego.ErrorController(&controllers.ErrorController{})

	// Register template functions.
	beego.AddFuncMap("i18n", i18n.Tr)
	beego.Run()
}
